package cn.gdcp.imgchange;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;

public class MainActivity extends AppCompatActivity {
    private ImageView imgDog;
    private Button btnNext;
    private int[] dogimgs={R.drawable.dog1,R.drawable.dog2,R.drawable.dog3,R.drawable.dog4,R.drawable.dog5};
    private int index=0;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        imgDog = findViewById(R.id.imgDog);
        btnNext = findViewById(R.id.btnNext);

        //new 快捷键 CTRL+SHIFT+空格
        btnNext.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                index=(index+1) % dogimgs.length;
                imgDog.setImageResource(dogimgs[index]);
            }
        });
    }
}
